home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / ggraph / RCS / points.c,v < prev    next >
Text File  |  1989-07-13  |  8KB  |  294 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     89.07.13.12.25.51;  author douglis;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     89.07.12.01.40.58;  author douglis;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @baseline from monet (?)
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @fixed bug with unintialized variable
  28. @
  29. text
  30. @#include <stdio.h>
  31. #include <errno.h>
  32. #include <strings.h>
  33. #include <math.h>
  34. #include "ggraph.h"
  35. #include "ggraphdefs.h"
  36.  
  37. /****************************************************************
  38.  *                                *
  39.  *    plotpoints - write the points of a line            *
  40.  *                                *
  41.  ****************************************************************/
  42. plotpoints () {
  43.     register int    i;
  44.     register float   llabxl, llabyl;
  45.     register float oscalex, oscaley;
  46.     int clipped = 0;
  47.     
  48.     for (curline = 0; ((curline != cg.maxlines) && (cl != NULL)); ++curline) {
  49.     if (cl->lonoff) {
  50.         if (symbsw) {
  51.         for (i = 0; i < cl->maxpoint; i++) {
  52.         /* put a circle around the point */
  53.             if(cg.logxsw){/* reset scale for logs */
  54.               oscalex = cg.scalex;/* save old scale */
  55.               cg.scalex = (XPLOTMAX - cg.xorigin) /
  56.             cg.numtickx;
  57.               graphx = ((( (float) (log10((double)cl->xpoints[i])/
  58.             log10((double)cg.logxtick)))
  59.              - cg.xoffset) * cg.scalex) + cg.xorigin;
  60.               cg.scalex = oscalex;
  61.             }else
  62.               graphx = ((cl->xpoints[i] - cg.xoffset) * cg.scalex)
  63.             + cg.xorigin;
  64.             if(cg.logysw){
  65.               oscaley = cg.scaley;
  66.               cg.scaley = (YPLOTMAX - cg.yorigin) / 
  67.             cg.numticky;
  68.               graphy = (((float)(log10((double)cl->ypoints[i])/
  69.             log10((double)cg.logytick))
  70.              - cg.yoffset) * cg.scaley) + cg.yorigin;
  71.               cg.scaley = oscaley;
  72.             }else
  73.               graphy = ((cl->ypoints[i] - cg.yoffset) * cg.scaley)
  74.             + cg.yorigin;
  75.             if (!((graphy < 0.0) || (graphy > 512.0) ||
  76.                 (graphx < 0.0) || (graphx > 512.0))){
  77.                 draw_symbol(cl->mtype, graphx, graphy);
  78.             }else
  79.             fprintf (stderr,
  80.             "%s: Symbol point out of range x %f y %f\npoint %f %f\n", 
  81. graphname, graphx, graphy, cl->xpoints[i], cl->ypoints[i]);
  82.         }
  83.         }
  84.     /* connect the dots */
  85.         if (cl->ctype) {
  86.         if(version == SUN_GREMLIN)
  87.           fprintf (outfile, "%s\n",
  88.               (cl->ctype == LINE) ? "VECTOR" : "CURVE");
  89.         else
  90.           fprintf (outfile, "%d\n", cl->ctype);
  91.         for (i = 0; i < cl->maxpoint; i++) {
  92.             if(cg.logxsw){
  93.               oscalex = cg.scalex;
  94.               cg.scalex = (XPLOTMAX - cg.xorigin) /
  95.              cg.numtickx;
  96.               graphx = (((float)(log10((double)cl->xpoints[i])/
  97.             log10((double)cg.logxtick))
  98.              - cg.xoffset) * cg.scalex) + cg.xorigin;
  99.               cg.scalex = oscalex;
  100.             }else
  101.               graphx = ((cl->xpoints[i] - cg.xoffset) * cg.scalex)
  102.             + cg.xorigin;
  103.             if(cg.logysw){
  104.               oscaley = cg.scaley;
  105.               cg.scaley = (YPLOTMAX - cg.yorigin) / 
  106.             cg.numticky;
  107. /* printf("point %f partial %f off %f scale %f\n",
  108.  cl->ypoints[i],(float)(log10((double)cl->ypoints[i])/
  109.   log10((double)cg.logytick)),cg.yoffset,cg.scaley); */
  110.               graphy = (((float)(log10((double)cl->ypoints[i])/
  111.             log10((double)cg.logytick))
  112.              - cg.yoffset) * cg.scaley) + cg.yorigin;
  113.               cg.scaley = oscaley;
  114.             }else
  115.               graphy = ((cl->ypoints[i] - cg.yoffset) * cg.scaley)
  116.             + cg.yorigin;
  117.             if ((graphy < 0.0) || (graphy > 512.0) ||
  118.                 (graphx < 0.0) || (graphx > 512.0)) {
  119.                 fprintf (stderr,
  120.             "%s: Line point out of range x %f y %f\npoint %f %f\n", 
  121.             graphname, graphx, graphy, cl->xpoints[i],
  122.             cl->ypoints[i]);
  123.                 if (!clipped) {
  124.                     fprintf(outfile, 
  125.                        (version == SUN_GREMLIN) ?
  126.                        "*\n" : "-1.00 -1.00\n");
  127.                     fprintf (outfile, "%d %d\n%d\n",
  128.                         cl->ltype, 0, 0);
  129.                     clipped = 1;
  130.                 } 
  131.             } else {
  132.                 if (clipped) {
  133.                     fprintf (outfile, "%d\n", cl->ctype);
  134.                     clipped = 0;
  135.                 } 
  136.             fprintf (outfile, "%4.1f %4.1f\n", graphx, graphy);
  137. /*            if(ddebug)printf ("point %4.1f %4.1f\n",
  138.                            graphx, graphy);*/
  139.             }
  140.         }
  141.         fprintf(outfile, (version == SUN_GREMLIN) ? "*\n" : "-1.00 -1.00\n");
  142.         fprintf (outfile, "%d %d\n%d\n", cl->ltype, 0, 0);
  143.         }
  144.         if (cl->llabsw) {
  145.         if (cl->llabel.t_text[0] == NULL)
  146.             strcpy (cl->llabel.t_text, cl->lname);
  147.         if (!cl->llabel.t_xpos)
  148.             if(cg.logxsw){
  149.               oscalex = cg.scalex;
  150.               cg.scalex = (XPLOTMAX - cg.xorigin) / 
  151.             cg.numtickx;
  152.               llabxl = (((float)(log10((double)cl->xpoints[cl->maxpoint-1])/
  153.             log10((double)cg.logxtick))
  154.              - cg.xoffset) * cg.scalex) + cg.xorigin;
  155.               cg.scalex = oscalex;
  156.             }else
  157.             llabxl = ((cl->xpoints[cl->maxpoint - 1] -cg.xoffset) * cg.scalex)
  158.             + cg.xorigin+5.0;
  159.         else
  160.             llabxl = (cl->llabel.t_xpos * cg.scalex) + cg.xorigin;
  161.         if (!cl->llabel.t_ypos)
  162.             if(cg.logysw){
  163.               oscaley = cg.scaley;
  164.               cg.scaley = (YPLOTMAX - cg.yorigin) /
  165.              cg.numticky;
  166.               llabyl = (((float)(log10((double)cl->ypoints[cl->maxpoint-1])/
  167.             log10((double)cg.logytick))
  168.              - cg.yoffset) * cg.scaley) + cg.yorigin;
  169.               cg.scaley = oscaley;
  170.             }else
  171.             llabyl = ((cl->ypoints[cl->maxpoint - 1] - cg.yoffset)
  172.               * cg.scaley) + cg.yorigin + 5.0;
  173.         else
  174.             llabyl = ((cl->llabel.t_ypos - cg.yoffset) * cg.scaley) + 
  175.             cg.yorigin;
  176. if(debug)printf("labels %f %f point %f %f high %d scale %f\n", llabxl, llabyl, 
  177.  cl->xpoints[cl->maxpoint -1],cl->ypoints[cl->maxpoint -1], cl->maxpoint, 
  178. cg.scalex);
  179.         drawctext (llabxl, llabyl, cl->llabel.t_font, 
  180.           cl->llabel.t_size, cl->llabel.t_text,
  181.             CENTERLEFT_TEXT);
  182.         }
  183.     }
  184.     }
  185. }
  186. /****************************************************************
  187.  *                                *
  188.  *    readpoints - read the points in             *
  189.  *            returns point number            *
  190.  *                                *
  191.  ****************************************************************/
  192. int     readpoints (infile, line_name)
  193. FILE *infile;
  194. char   *line_name;
  195. {
  196.     int     count;
  197.     register int    i;
  198.     register int    done;
  199.     float   x,
  200.             y;
  201.     float   hix,
  202.             hiy,
  203.             lox,
  204.             loy;
  205.     char    iline[80];
  206.     char   *fgets ();
  207.  
  208.     count = 0;
  209.     while (count != -1) {    /* wait for EOF */
  210.     count = 0;
  211.     done = FALSE;
  212.     hix = hiy = 0.0;
  213.     lox = loy = HUGE;
  214.     curline++;
  215.                 /* allocate a line structure */
  216.     cl = (struct aline *)malloc(sizeof(struct aline));
  217.     cl->forw_line = NULL;    /* link chain */
  218.     cl->back_line = NULL;
  219.     cg.lines[curline+1] = NULL;/* terminate chain */
  220.     cl->mtype = -1;
  221.     cl->ltype = -1;
  222.     cl->ctype = -1;
  223.     cl->llabel.t_size = -1;
  224.     cl->llabel.t_font = -1;
  225.     cl->llelabel.t_size = -1;
  226.     cl->llelabel.t_font = -1;
  227.     strcpy (cl->lname, line_name);
  228.     cl->llabel.t_size = -1;
  229.     cl->llabel.t_font = -1;
  230.     cl->llabel.t_xpos = 0.0;
  231.     cl->llabel.t_ypos = 0.0;
  232.     cl->lonoff = 1;
  233.     cl->ctype = -1;
  234.     cl->mtype = -1;
  235.     cl->ltype = -1;
  236.     while (!done) {        /* loop around for a while */
  237.         if (fgets (iline, 80, infile) == NULL) {/* read numbers */
  238.         done = TRUE;    /* EOF stop reading */
  239.         count = -1;    /* let reader know */
  240.         }
  241.         else
  242.         if (strncmp ("dae", iline, 3) == 0) {
  243.         /* End-of-line-segment */
  244.             done = TRUE;
  245.         }
  246.         else {        /* calculate point on graph */
  247.             sscanf (iline, "%f %f", &x, &y);
  248.             if (x > hix)
  249.             hix = x;
  250.             if (x < lox)
  251.             lox = x;
  252.             if (y > hiy)
  253.             hiy = y;
  254.             if (y < loy)
  255.             loy = y;
  256.             cl->xpoints[count] = x;
  257.             cl->ypoints[count] = y;
  258.             count++;
  259.         }
  260.     }
  261.     /* set count of number of points */
  262.     cl->maxpoint = count;
  263.     cl->minx = lox;
  264.     cl->miny = loy;
  265.     cl->maxx = hix;
  266.     cl->maxy = hiy;
  267.     cg.xoffset = lox;
  268.     cg.yoffset = loy;
  269.     if (cg.gminx > lox)
  270.         cg.gminx = cl->minx;
  271.     if (cg.gminy > loy)
  272.         cg.gminy = cl->miny;
  273.     if (cg.gmaxx < hix)
  274.         cg.gmaxx = cl->maxx;
  275.     if (cg.gmaxy < hiy)
  276.         cg.gmaxy = cl->maxy;
  277.  
  278.     return (curline + 1);    /* return point number */
  279.     }
  280.     return (curline + 1);    /* return point number */
  281. }
  282. @
  283.  
  284.  
  285. 1.1
  286. log
  287. @Initial revision
  288. @
  289. text
  290. @d17 1
  291. a17 1
  292.     int clipped;
  293. @
  294.